const vscode = require('vscode');
const fs = require('fs');
const child_process = require('child_process');
const path = require('path');

const DIRNAME =  __dirname + '\\..\\..\\';

module.exports = function(context) {
    context.subscriptions.push(vscode.commands.registerCommand('extension.test', run));
};

function run() {
    var workerProcess = child_process.exec('python "'+ DIRNAME +'pymodel/predict.py"', function (error, stdout, stderr) {
        if (error) {
            console.log(error.stack);
            console.log('Error code: '+error.code);
            console.log('Signal received: '+error.signal);
        }
        console.log('stdout: ' + stdout);
        console.log('stderr: ' + stderr);
    });
    
    workerProcess.on('exit', function (code) {
        console.log('子进程已退出，退出码 '+code);
        if(code==0) {
            vscode.window.showInformationMessage('特征依恋预测成功');
            vscode.commands.executeCommand('extension.showres').then(result => {
                console.log('命令结果', result);
            });
        }
        else if(code==2) {
            vscode.window.showWarningMessage('该文件不存在特征依恋');
        }
        else {
            vscode.window.showErrorMessage('特征依恋预测失败');
        }
    });
}